/*
 * $Id: api_getuptime.c,v 1.1 2006-02-22 04:51:51 bacon Exp $
 */

#include <xp/sys/api.h>

#if defined(_WIN32)
	#include <pdh.h>
#elif defined(__linux)
	#include <sys/sysinfo.h>
	#include <sys/sysctl.h>
#elif defined(__FreeBSD__)
	#include <kvm.h>
	#include <fcntl.h>
	#include <sys/sysctl.h>
#elif defined(sun)||defined(__sun)
	#include <sys/sysinfo.h>
#else
	#include <sys/sysctl.h>
#endif

int xp_getuptime (xp_time_t* uptime)
{
#if defined(_WIN32)

/*
	PDH_STATUS  status;
	HQUERY      perfQuery = XP_NULL;
	HCOUNTER    uptimeCounter;
	char        uptimeCounterPath[] = "\\\\.\\System\\System Up Time";
	PDH_FMT_COUNTERVALUE uptimeValue;

	seconds = 0;

	if(PdhOpenQuery(XP_NULL, 0, perfQuery) != ERROR_SUCCESS) return -1;

	status = PdhAddCounter(perfQuery, uptimeCounterPath,
                            0, &uptimeCounter);
	if(status != ERROR_SUCCESS) return -1;


	status = PdhCollectQueryData (perfQuery);
	if(status != ERROR_SUCCESS) return -1;

	status = PdhGetFormattedCounterValue ( uptimeCounter, 
		PDH_FMT_LARGE , NULL, &uptimeValue );
	if(status != ERROR_SUCCESS) return -1;

	PdhCloseQuery (&perfQuery);
	seconds = (DWORD)uptimeValue.largeValue;
*/

	return -1;
#elif defined(__linux)
	struct sysinfo info;

	if (sysinfo (&info) == -1) return -1;
	*uptime = (xp_time_t)info.uptime * XP_MSEC_IN_SEC;
	return 0;
#else
	return -1;
#endif

}
